using System.Reflection;
using Microsoft.SharePoint.Administration;

namespace ActivityFeed.SharePoint.Sample
{
    public class ConfigModificator
    {
        private readonly string assemblyFullName;
        private System.Collections.ObjectModel.Collection<SPWebConfigModification> collection;


        public ConfigModificator(System.Collections.ObjectModel.Collection<SPWebConfigModification> collection)
        {
            this.assemblyFullName = Assembly.GetExecutingAssembly().FullName;
            this.collection = collection;
        }

        public void EnsureSection(string sectionName, string path)
        {
            var modification = new SPWebConfigModification();
            modification.Path = path;
            modification.Name = sectionName;
            modification.Value = string.Format("<{0}></{0}>", sectionName);
            modification.Owner = assemblyFullName;
            modification.Sequence = 100;
            modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection;
            collection.Add(modification);
        }

        public void EnsureChildNode(string path, string name, string value)
        {
            var modification = new SPWebConfigModification();
            modification.Path = path;
            modification.Name = name;
            modification.Value = value;
            modification.Owner = assemblyFullName;
            modification.Sequence = 100;
            modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
            collection.Add(modification);
        }

    }
}